class ToolGrid
{
  int nb;
  AABB boundingBox;
  float posBaseline; // [0;1]
  float alpha = 100.0;
  
  ToolGrid(int nb)
  {
    this.nb = nb;
    this.boundingBox = new AABB( new Vec3D(width/2,height/2,0),  new Vec3D(width,height,0));
    this.posBaseline = 0.65;
  }
  
  void setAlpha(float a)
  {
    this.alpha = a;
  }
  
  void setExtent(float w)
  {
    this.boundingBox.setExtent(new Vec3D(w,w,0)); 
  }
  
  void setNumber(int nb)
  {
    this.nb = nb;
  }
  
  void setBaseLine(float y)
  {
    posBaseline = y;
  }
  
  float x()
  {
    return this.boundingBox.x-getWidth()/2;
  }

  float y()
  {
    return this.boundingBox.y-getHeight()/2;
  }

  
  float getWidth()
  {
    return this.boundingBox.getExtent().x;
  }

  float getHeight()
  {
    return this.boundingBox.getExtent().y;
  }
  
  void draw()
  {
    pushStyle();
    noFill();
    stroke(128,alpha);    
    strokeWeight(1);
    pushMatrix();
    translate(this.boundingBox.x-this.getWidth()/2,this.boundingBox.y-this.getHeight()/2,0);
    float step = this.boundingBox.getExtent().x / float(nb);
    float x=0,y=0;
    for (int i=0;i<=nb;i++){
      line(int(x),0,int(x),int(this.boundingBox.getExtent().y));
      x += step;
    }
    for (int i=0;i<=nb;i++){
      line(0,int(y),int(this.boundingBox.getExtent().x),int(y));
      y += step;
    }
    stroke(200,0,0,this.alpha);
    y = posBaseline*getHeight();
    line(0,y,getWidth(),y);
    rectMode(CENTER);
    noStroke();
    fill(200,0,0,this.alpha);
    float s=4;
    rect(0,y,s,s);
    rect(getWidth(),y,s,s);

    popMatrix();
    popStyle();
  }
  
}
